# depandencies:
# sudo apt install hostapd
# sudo apt install udhcpd

SLAM_ROOT="/opt/carto"
WLAN="wlx1ca770e744ca"
NET="24"
SUDO(){
  echo 1 | sudo -S $*
}


SUDO ip addr > $SLAM_ROOT/ip.log


HOSTAPD_CONF="
# hostapd.conf
interface=$WLAN
driver=nl80211
ssid=Baer1
hw_mode=g
channel=6
wpa=2
wpa_passphrase=123456789
wpa_key_mgmt=WPA-PSK
"

echo "$HOSTAPD_CONF" > $SLAM_ROOT/hostapd.conf

UDHCPD_CONF="
# udhcpd.conf
interface         $WLAN
start             192.168.$NET.2
end               192.168.$NET.254

auto_time         60
decline_time      3600
confilict_time    3600
offer_time        60
min_lease         10

opt    dns        8.8.8.8 1.1.1.1
opt    router     192.168.$NET.1
option subnet     255.255.255.0
option lease      999999
"

echo "$UDHCPD_CONF" > $SLAM_ROOT/udhcpd.conf

SUDO killall hostapd udhcpd

sleep 3

SUDO nmcli device set $WLAN managed off
SUDO iw dev $WLAN set txpower fixed 1800
# background
SUDO hostapd $SLAM_ROOT/hostapd.conf -B
SUDO udhcpd $SLAM_ROOT/udhcpd.conf

SUDO ip addr add 192.168.$NET.1/24 dev $WLAN

SUDO ip route add default via 192.168.$NET.1 dev $WLAN
SUDO ip route add 192.168.$NET.0/24 dev $WLAN
